package sv.main;

public class Game {
	
	public enum State {WATER , SHIP, HITSHIP, HITWATER, PSEUDOSHIP};
	private State[][] tile;
	private Byte[][] shipId;
	private Byte[] shipHp;
	private Boolean isServer;
	private Boolean selfReady;
	private Boolean allReady;
	private Boolean oppReady;
	private Byte shots;
	private Boolean lost;
		
	public Game(){
		tile = new State[10][10];
		shipId = new Byte[10][10];
		for (byte i=0; i<10; i++){
			for (byte j=0; j<10; j++){
				tile[i][j] = State.WATER;
				shipId[i][j] = 0;
			}
		}
		shipHp = new Byte[5];
		shipHp[0] = 2;
		shipHp[1] = 3;
		shipHp[2] = 3;
		shipHp[3] = 4;
		shipHp[4] = 5;
		selfReady = false;
		allReady = false;
		oppReady = false;
		shots = 0;
		lost = false;
	}
	
	public void changeTile(int x, int y, State newState){
		tile[x][y] = newState;
	}
	
	public State getTile(int x, int y){
		return tile[x][y];
	}
	
	public void setShipId(int x, int y, byte id){
		shipId[x][y] = id;
	}
	
	public Byte getShipId(int x, int y){
		return shipId[x][y];
	}
	
	public void shipHit(byte shipId){
		shipHp[shipId-1]--;
	}
	
	public Byte getShipHp(byte shipId){
		return shipHp[shipId-1];
	}
	
	public Boolean isServer(){
		return isServer;
	}
	
	public void setServer(Boolean serverOrNotServer){
		isServer = serverOrNotServer;
	}
	
	public Boolean isSelfReady(){
		return selfReady;
	}
	
	public void setSelfReady(Boolean areYouReady){
		selfReady = areYouReady;
	}
	
	public Boolean areAllReady(){
		return allReady;
	}
	
	public void setAllReady(Boolean areAllReady){
		allReady = areAllReady;
	}
	
	public Boolean isOppReady(){
		return oppReady;
	}
	
	public void setOppReady(Boolean isOppReady){
		oppReady = isOppReady;
	}

	public synchronized Byte getShots(){
		return shots;
	}
	
	public synchronized void incShots(){
		shots++;
	}
	
	public synchronized void decShots(){
		shots--;
	}
	
	public Boolean iLost(){
		return lost;
	}
	
	public void iLose(){
		lost = true;
	}
}
